package com.theopentutorials.jdbc.dao;

//DAO classes implements Data Access Object (DAO) pattern which encapsulates access to the data source.
//
//This class defines methods for each query, 
//where we first create connection object using ConnectionFactory (by calling ConnectionFactory.getConnection()).
//Using this connection object we create statement and execute queries.

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.theopentutorials.jdbc.db.ConnectionFactory;
import com.theopentutorials.jdbc.db.DbUtil;
import com.theopentutorials.jdbc.to.Employee;
 
public class EmployeeDAO {
    private Connection connection;
    private Statement statement;
 
    public EmployeeDAO() { }
     
    public Employee getEmployee(int employeeId) throws SQLException {
        String query = "SELECT * FROM employee WHERE emp_id=" + employeeId;
        ResultSet rs = null;
        Employee employee = null;
        try {
            connection = ConnectionFactory.getConnection();
            statement = connection.createStatement();
            rs = statement.executeQuery(query);
           // . . . .
           // . . . .
        } finally {
            DbUtil.close(rs);
            DbUtil.close(statement);
            DbUtil.close(connection);
        }
        return employee;
}
    
    
    
}